$().ready(function(){
    let page = {
        p:1,
        num:10,
        status:0,
        service_class:1
    }
    function init(){
        getCommentList(page.p,page.status,page.service_class);
    }
    init();
    //获取列表
    function getCommentList(p,status,type){
        getAjax(`${global.apiUrl}/community_get_shop_tell`,res=>{
            console.log(res);
            let html = '';
            let list = res.list;
            if(res.list.length != 0){
                $('#secondHand-page').paging({
                    totalSize:res.count,
                    totalPage:Math.ceil(res.count/page.num),
                    pageNo:page.p,
                    callback(num){
                        page.p = num;
                        getCommentList(num,page.status,page.service_class)
                    }
                })
                for(let i in list){
                    html += `
                     <tr>
                        <td>${list[i].shop_name}</td>
                        <td>${list[i].phone}</td>
                        <td class="comment-content">${list[i].tell}</td>
                        <td >${list[i].date}</td>
                        <td>${list[i].status == 0?'等待处理':'已处理'}</td>
                        <td style="color:#0d8ddb">
                            <span class="sub-btn ${list[i].status==0?'disblock':'disnone'}" style="margin-left: 5px" data-id="${list[i].id}">处理确认</span>
                        </td>
                    </tr>
                `
                }

            }else{
                $('#secondHand-page').paging({
                    totalSize:0,
                    totalPage:0,
                    pageNo:0,
                    callback(num){
                        getCommentList(num,page.status,page.service_class)
                    }
                })
                html = `
                    <tr>
                        <td colspan="6">暂无数据</td>
                    </tr>
                `
            }
            $('#product_list').html(html);
        },{
            p:p,
            num:page.num,
            community_id:global.community_id,
            status:status,//0未处理  1已处理
            type:type,//1家政服务  2上门服务
            type2:1//1社区 2用户
        })
    }
    //切换处理结果
    $('#goods_class').on('change',function(){
        let status = $(this).children('option:selected').val();
        page.status = status;
        getCommentList(page.p,status,page.service_class);
    });
    //切换服务类别
    $('#service_class').on('change',function(){
        let service_class = $(this).children('option:selected').val();
        page.service_class = service_class;
        getCommentList(page.p,page.status,service_class);
    });
    //确认处理
    $('#product_list').on('click','.sub-btn',function(){
        let r = confirm('是否确认完成意见处理？');
        let id = $(this).data('id');
        if(r){
            getAjax(`${global.apiUrl}/cl_shop_tell`,res=>{
                console.log(res);
                if(res == 1){
                   alert('已确认完成处理！');
                   getCommentList(page.p,page.status,page.service_class);
                }
            },{
                type:page.service_class,
                id:id
            })
        }
    })
});
